const util = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: getApp().globalData.imgUrl,
    imgUrls: getApp().globalData.imgUrls,
    roulsArr: " 1.活动期间累计充值达到额度即可开启红包奖励。2.开出的红包奖励在个人信息的“我的红包”界面查看。3.开出的红包有使用有效4.本次活动最终解释权归团队所有。期，请及时使用。",
    isAdress: false,
    show: false,
    noVip: false,
    tips: false
  },
  /**
   * 生命周期函数--监听页面加载
   */

  isAdress() {
    this.setData({
      isAdress: !this.data.isAdress,
      show: false,
    })
  },
  onLoad: function(options) {
    this.data.activity_id = options.jump_id
    console.log(options, this.data.activity_id,111)
    this.golden_eggs()
  },
  golden_eggs() {
    util.API('newaddress/Purchase/golden_eggs', {
      activity_id: this.data.activity_id,
    }).then(res => {
      let {
        code,
        data,
        msg
      } = res
      if (code == 200) {
        this.setData({
          data,
          roulsArr: data.data.activity_content
        })
      }else{
        wx.showToast({
          title: msg,
          icon: 'none',
        })
      }
    })
  },
  close() {
    this.setData({
      show: false,

    })
  },
  boom() {
    var that = this
    return new Promise(function(resolve, reject) {
      
      util.API('newaddress/Purchase/boom', {
        activity_id: that.data.activity_id,
      }).then(res => {
        resolve(res)
      })

    })

  },
  hiddenShow() {
    this.boom().then(res => {
      let {
        code,
        data,
        msg
      } = res
      if (code == 200) {
        this.setData({
          prize: data,
          tips: null
        })
        this.golden_eggs()
      } else {
        if (res.msg == '非会员用户不可参加活动') {
          this.setData({
            noVip: true,
          })
        }
        this.setData({
          tips: res.msg,
          prize: null
        })
      }
      this.setData({
        show: true
      })

    })
  },
  bindinput(e) {
    this.setData({
      [e.currentTarget.dataset.name]: e.detail.value
    })
  },
  submitAddress() {
    let {
      prize,
      truename,
      address,
      phone
    } = this.data;

    if (!truename || !address || !phone) {
      wx.showToast({
        title: '请填写完整信息',
        icon: 'none',
      })
      return
    } else {
      if (phone.length != 11) {
        wx.showToast({
          title: '请填写正确手机号',
          icon: 'none',
        })
        return
      }
    }
    util.API('newaddress/Purchase/user_info', {
      truename,
      address,
      phone,
      log_id: prize.log_id,
    }).then(res => {
      if (res.code == 200) {
        wx.showToast({
          title: '地址提交成功',
          icon: 'none',
        })
        this.setData({
          isAdress: !this.data.isAdress,
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'none',
        })
      }
    })



  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */

})